import {
	fileURLToPath,
	URL
} from 'node:url'

import {
	defineConfig
} from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {
	ElementPlusResolver
} from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
	base: "./",
	plugins: [
		vue(),
		AutoImport({
			resolvers: [ElementPlusResolver()],
		}),
		Components({
			resolvers: [ElementPlusResolver()],
		}),
	],
	resolve: {
		alias: {
			'@': fileURLToPath(new URL('./src',
				import.meta.url))
		}
	},
	// 跨域问题解决
	server: {
		host: '0.0.0.0', // 监听所有 IP
		cors: true,
		proxy: {
			'/api' : {
				target: 'https://platform.easys.co',
				changeOrigin: true,
				ws: true,
				secure: true,
				// rewrite: (path) => path.repeat(/^\/api/, '') //重新将路径改写到/store上面
				pathRewrite: {
					'^/api': ''
				}
			}
		}
	},
	// devServer: { // 环境配置
    //     proxy: 'http://127.0.0.1:5173/', // 配置代理，将请求转发到指定的地址
    //     host: '127.0.0.1', // 指定主机地址
    //     port: '443', // 指定端口号
    //     open: true // 是否自动打开浏览器
    // }
})



